package name.huzhenbo.java.patterns.state;

class DoorManager {
    private static final DoorState OPENED_STATE = new OpenedDoor();
    private static final DoorState CLOSED_STATE = new ClosedDoor();


    private DoorState doorState;
    private DoorAction doorAction;

    public DoorManager() {
        this.doorAction = new DoorAction();
        this.doorState = CLOSED_STATE;
    }

    public DoorState getState() {
        return doorState;
    }

    public void open() {
        doorState.open(this);
    }

    public void close() {
        doorState.close(this);
    }

    public void executeOpen() {
        doorAction.open();
    }

    public void setOpened() {
        doorState = OPENED_STATE;
    }

    public void executeClose() {
        doorAction.close();
    }

    public void setClosed() {
        doorState = CLOSED_STATE;
    }

    public void executeAlarm() {
        doorAction.alarm();
    }

    public DoorAction getDoorAction() {
        return doorAction;
    }
}
